<?php

namespace app\merchant\controller\apps\sharp;

use app\merchant\controller\Base;
use app\merchant\model\sharp\Setting as SettingModel;

/**
 * 整点秒杀设置
 * Class Setting
 * @package app\merchant\controller\apps\sharp
 */
class Setting extends Base
{
    /**
     * 秒杀设置获取详情
     * @return array|mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {

        $values = SettingModel::getItem('basic');
        return $this->renderSuccess($values,'查询成功');

    }


    /**
     * 秒杀设置
     * @return array|mixed
     * @throws \think\exception\DbException
     */
    public function setting()
    {
        $param = $this->postData();
        if(!isset($param['order_close']) || isZeroNumeric($param['order_close'])){
            return $this->renderError([],"参数格式错误");
        }

        $model = new SettingModel;
        if ($model->edit('basic', $param)) {
            return $this->renderSuccess([],'编辑成功');
        }
        return $this->renderError([],$model->getError() ?: '编辑失败');
    }

}